import {
  request
} from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods: [],
    isFocus: false,
    inpValue:""
  },
  TimeId: -1,
  handleInput(e) {
    const {
      value
    } = e.detail
    clearTimeout(this.TimeId)

    if (!value.trim()) {

      this.setData({
        goods: [],
        isFocus: true
      })

      return;
    }

    this.setData({
      isFocus: true
    })

    this.TimeId = setTimeout(() => {
      this.qsearch(value)
    }, 1000)
  },
  async qsearch(query) {
    const res = await request({
      url: "/goods/qsearch",
      data: {
        query
      }
    })
    console.log(res);
    this.setData({
      goods: res
    })
  },

  handleCancel(){
    this.setData({
      inpValue:"",
      isFocus:false,
      goods:[]
    })
  }


})